package com.shangrila.web.common;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;

public abstract class ShangrilaActionSupport {
	
	protected final String SUCCESS="success";
	protected final String ERROR="error";
	protected final String INPUT="input";
	
	/**获取HttpServletRequest*/
	protected HttpServletRequest getHttpServletRequest(){
		return (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
	}
	/**获取Session的Map对象*/
	protected Map<String, Object> getSession(){
		return ActionContext.getContext().getSession();
	}
	/**获取HttpSession*/
	protected HttpSession getHttpSession(){
		return getHttpServletRequest().getSession();
	}
	/**获取HttpServletResponse*/
	protected HttpServletResponse getHttpServletResponse(){
		return (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
	}
	/**用户已经登录*/
	protected boolean isLogin(){
		return new UserTrackInfo(getHttpServletRequest()).isLogin();
	}
	/**获取客户端请求的ip地址*/
	protected String getIpAddress(){
		return new UserTrackInfo(getHttpServletRequest()).getIpAddress();
	}
}
